package com.scau.ums.service.imp.lostAndFoundInfo;

import com.scau.ums.mapper.LostandfoundinfoMapper;
import com.scau.ums.model.Lostandfoundinfo;
import com.scau.ums.model.LostandfoundinfoExample;
import com.scau.ums.service.LostAndFoundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xfy
 * @version 1.0
 * @date 2019/8/8 16:41
 */
@Service
public class LostAndFoundImp implements LostAndFoundService {
    @Autowired
    LostandfoundinfoMapper lostandfoundinfoMapper;

    @Override
    public List<Lostandfoundinfo> getLostAndFoundInfoByState(String state) {
        List<Lostandfoundinfo> list = new ArrayList<>();
        LostandfoundinfoExample lostandfoundinfoExample = new LostandfoundinfoExample();
        LostandfoundinfoExample.Criteria criteria = lostandfoundinfoExample.createCriteria();
        criteria.andStateEqualTo(state);
        list = lostandfoundinfoMapper.selectByExample(lostandfoundinfoExample);
        return list;
    }

    @Override
    public void verifyPass(Integer id) {
        Lostandfoundinfo lostandfoundinfo = new Lostandfoundinfo();
        lostandfoundinfo.setId(id);
        lostandfoundinfo.setState("审核通过");
        lostandfoundinfoMapper.updateByPrimaryKeySelective(lostandfoundinfo);
    }

    @Override
    public void verifyFail(Integer id) {
        Lostandfoundinfo lostandfoundinfo = new Lostandfoundinfo();
        lostandfoundinfo.setId(id);
        lostandfoundinfo.setState("审核不通过");
        lostandfoundinfoMapper.updateByPrimaryKeySelective(lostandfoundinfo);
    }

    @Override
    public void setIsFounded(Integer id, String isFounded) {
        Lostandfoundinfo lostandfoundinfo = new Lostandfoundinfo();
        lostandfoundinfo.setId(id);
        lostandfoundinfo.setIsfounded(isFounded);
        lostandfoundinfoMapper.updateByPrimaryKeySelective(lostandfoundinfo);
    }

    @Override
    public List<Lostandfoundinfo> getLostAndFoundById(String userId, String userType) {

        LostandfoundinfoExample lostandfoundinfoExample = new LostandfoundinfoExample();
        LostandfoundinfoExample.Criteria criteria = lostandfoundinfoExample.createCriteria();
        criteria.andPublisheridEqualTo(userId);
        criteria.andPublishertypeEqualTo(userType);
        return lostandfoundinfoMapper.selectByExample(lostandfoundinfoExample);
    }
}
